<template>
  <div class="app-container">
    <div class="information ">
      <div>班级信息</div>
      <span class="numInfo">
        班级总人数：
        <el-input
          v-model="sum"
          placeholder="请填写"
          style="width: 140px"
        />
      </span>
      <span class="numInfo">
        出席人数：
        <el-input
          v-model="present"
          placeholder="请填写"
          style="width: 140px"
        />
      </span>
      <span class="numInfo">
        缺席人数：
        <el-input
          v-model="absent"
          placeholder="请填写"
          style="width: 140px"
          @change="setAbsent"
        />
      </span>
      <el-button size="small" type="success">提交</el-button>
    </div>
    <el-divider />
    <div class="table-header">民主评测表</div>
    <el-table
      :data="tableData"
      border
      style="width: 100%"
    >
      <el-table-column
        prop="id"
        label="学号"
        width="200"
      />
      <el-table-column
        prop="name"
        label="姓名"
        width="200"
      />
      <el-table-column
        prop="pass"
        label="通过"
      >
        <template slot-scope="scope">
          <el-input
            v-model="tableData[scope.$index].pass"
            placeholder="请输入"
            @change="setFail(scope.row)"
          />
        </template>
      </el-table-column>
      <el-table-column
        prop="fail"
        label="失败"
      >
        <template slot-scope="scope">
          <el-input v-model="tableData[scope.$index].fail" placeholder="请输入" />
        </template>
      </el-table-column>
      <el-table-column
        prop="absent"
        label="弃权"
      >
        <template>
          <el-input v-model="absent_num" placeholder="请输入" />
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      sum: null,
      present: null,
      absent: null,
      absent_num: null,
      tableData: [{
        id: '2033051',
        name: '王小虎',
        pass: null,
        fail: null
      }, {
        id: '2033052',
        name: '王中虎',
        pass: null,
        fail: null
      }, {
        id: '2033053',
        name: '王大虎',
        pass: null,
        fail: null
      }]
    }
  },
  mounted() {
  },
  methods: {
    setAbsent() {
      this.absent_num = this.absent
    },
    setFail(row) {
      console.log(row)
      row.fail = this.sum - this.absent - row.pass
    }
  }
}
</script>

<style>
.information {
  height: 40px;
  line-height: 40px;
  font-size: 20px;
  font-weight: bolder;
  color: #d7690f;
  background-color: white;
  display: inline-block;
}
.numInfo{
  font-weight: lighter;
  color: #312d2b;
  font-size: 16px;
}
.numInfo:nth-child(n+2){
  margin: 0 10px;
}

.table-header{
  font-size: 20px;
  color: #5daf34;
  font-weight: bolder;
  margin-bottom: 10px;
}
</style>
